﻿<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<!--#include file="sha1.asp" -->
<%
Session.CodePage = 65001;
Response.Charset = "utf-8";

function trim(str){
	return (str+"").replace(/(^\s*)|(\s*$)/g,"");
}
function RQ(){
	return (Request.QueryString(arguments[0])()||"")+"";  // 如果参数不存在就返回空字符，否则返回结果字符串
}
function RF(){
	var emu = Request.Form(arguments[0]);
	if (emu){
		var arr = [];
		for (var i=1; i<=emu.Count; i++){
			arr[i-1] = emu.item(i);
		}
		return arguments[1] ? arr : arr[0];
	}else{
		return null;
	}
}
function xml2html(xml,xslfilepath){ // xmldom 可以是dom对象，也可以是xml的路径, xslfilepath 是 xsl 的路径
	if( typeof xml == "string"){
		var dom = new ActiveXObject("MSXML2.DOMDocument");
		if(xml.substring(0,1)=="<"){
			dom.loadXML(xml);
		}else{
			dom.load(xml);
		}
		if(dom.parseError.errorCode!=0){
			return dom.parseError.reason +"<br />"+ xml;
		}
	}else{
		var dom = xml;
	}	
	
	var xmlxslt = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
	xmlxslt.async = false;
	xmlxslt.preserveWhiteSpace = false;
	xmlxslt.validateOnParse = false;
	xmlxslt.resolveExternals = true;
	xmlxslt.load( xslfilepath );
	
	if(xmlxslt.parseError.errorCode!=0){
		return xmlxslt.parseError.reason +"<br />"+ xslfilepath;
	}
	
	var xslt = new ActiveXObject("MSXML2.XSLTemplate");
	xslt.stylesheet = xmlxslt;
	var xslProc = xslt.createProcessor();
	xslProc.input = dom;
	xslProc.transform();
	return xslProc.output;
}
function getRnd(){
	var n = parseInt(Math.random()*1000000).toString();
	switch(n.length){
		case 1 : n="00000"+n; break;
		case 2 : n="0000"+n; break;
		case 3 : n="000"+n; break;
		case 4 : n="00"+n; break;
		case 5 : n="0"+n; break;
	}
	return n;
}

function getNowTime(type){
	//type: 1:20090310173456123;  2:2009-03-10T17:23:56.123+08:00;  3:20090310;    4:2009-03-10 17:23:56
	var d = new Date();
	var y = d.getFullYear();
	var m = (d.getMonth()+1).toString();
	var dd = d.getDate().toString();
	var h = d.getHours().toString();
	var mm = d.getMinutes().toString();
	var s = d.getSeconds().toString();
	 
	var ss = d.getUTCMilliseconds().toString();
	if(ss.length==1){ss = "00" + ss;}
	if(ss.length==2){ss = "0" + ss;}
	
	var str = "";
	if(!type)type=1;
	switch(type.toString()){
		case "1" :
			str = y+(m.length<2?"0"+m:m)+(dd.length<2?"0"+dd:dd)+(h.length<2?"0"+h:h)+(mm.length<2?"0"+mm:mm)+(s.length<2?"0"+s:s)+ss+getRnd();
			break;
		case "2" :
			var tz = new Date().getTimezoneOffset();
			var minu = (tz % 60).toString();
			if(minu.length<2){minu = "0" + minu;}
			
			var hour = -1 * parseInt(tz / 60);
			var hs = Math.abs(hour).toString();
			hs = hs.length<2 ? "0"+hs : hs;
			str = y+"-"+(m.length<2?"0"+m:m)+"-"+(dd.length<2?"0"+dd:dd)+"T"+(h.length<2?"0"+h:h)+":"+(mm.length<2?"0"+mm:mm)+":"+(s.length<2?"0"+s:s)+"."+ss+((hour<0 ? "-" : "+") + hs + ":" + minu);
			break;
		case "3" :
			str = y+(m.length<2?"0"+m:m)+(dd.length<2?"0"+dd:dd);
		case "4" :
			str = y+"-"+(m.length<2?"0"+m:m)+"-"+(dd.length<2?"0"+dd:dd)+" "+(h.length<2?"0"+h:h)+":"+(mm.length<2?"0"+mm:mm)+":"+(s.length<2?"0"+s:s);
			break;
	}
	return str;
}
function getMaxID(n){
	var i = 0;
	var idfile = Server.MapPath("maxid.txt");
	var fso = new ActiveXObject("Scripting.FileSystemObject");
	var f = fso.OpenTextFile(idfile, 1, false);
	i = parseInt(f.ReadAll()+"");
	f.Close();
	f = fso.OpenTextFile(idfile, 2, false);
	if(!n){
		f.Write(i+1);
	}else{
		f.Write(i+n);
		var id = [];
		for(var k=i; k<i+n; k++){
			id.push(k);
		}
		i = id.join(",");
	}
	f.Close();
	return i;
}
var fav = {
	checkLogin : function(){
		var username = (Request.Cookies("loginUserName")+"").toLowerCase();
		var password = Request.Cookies("loginPassWord")+"";
		if(username=="" || password==""){
			fav.loginui();
			return false;
		}
		var fso = new ActiveXObject("Scripting.FileSystemObject");
		if(!fso.FileExists(Server.MapPath("userdata")+"\\"+Request.Cookies("loginUserName")+".xml")){
			fav.loginui();
			return false;
		}
		var dom = new ActiveXObject("MSXML2.DOMDocument");
		dom.setProperty('SelectionLanguage','XPath');
		dom.load(Server.MapPath("userdata")+"\\"+username+".xml");
		if(hex_sha1(dom.selectSingleNode("/root/password").text)!=password){
			fav.loginui();
			return false;
		}
		return true;
	},
	loginui : function(str){
		Response.Write(xml2html(str||"<root><loginUserName>"+Request.Cookies("loginUserName")+"</loginUserName></root>",Server.MapPath("xsl/login.xsl")));
	},
	login : function(){
		var username = RF("username").toLowerCase();
		var password = hex_sha1(RF("password"));
		var fso = new ActiveXObject("Scripting.FileSystemObject");
		if(!fso.FileExists(Server.MapPath("userdata")+"\\"+username+".xml")){
			fav.loginui("<root><loginUserName>"+username+"</loginUserName><error>用户不存在！</error></root>");
			return;
		}
		var dom = new ActiveXObject("MSXML2.DOMDocument");
		dom.load(Server.MapPath("userdata")+"\\"+username+".xml");
		if(dom.selectSingleNode("/root/password").text==password){		
			Response.Cookies("loginUserName") = username;
			Response.Cookies("loginPassWord") = hex_sha1(password);
			Response.Cookies("loginUserName").Expires = "July 31, 2018";
			Response.Cookies("loginPassWord").Expires = "July 31, 2018";
			Response.Redirect("?type=mgr");
		}else{
			fav.loginui("<root><loginUserName>"+username+"</loginUserName><error>密码错误！</error></root>");
		}
	},
	logout : function(){
			//Response.Cookies("loginUserName").Expires = "July 31, 1997";
			Response.Cookies("loginPassWord").Expires = "July 31, 1997";
			Response.Redirect("?type=loginui");
	},
	mgr : function(){
		var dom = new ActiveXObject("MSXML2.DOMDocument");
		dom.setProperty('SelectionLanguage','XPath');
		dom.load(Server.MapPath("userdata")+"\\"+Request.Cookies("loginUserName")+".xml");
		
		var page = RQ("page") || 1;
		if(isNaN(page)) page = 1;
		var catid = RQ("catid") || 0;
		
		var pagesize = 20;
		if(dom.parseError.errorCode!=0){
			Response.Write(dom.parseError.reason);
			return;
		}
		
		var para = dom.createNode(1,"para","");		
		para.setAttribute("page",page);
		para.setAttribute("catid",catid);
		para.setAttribute("pagesize",pagesize);
		dom.selectSingleNode("/root").appendChild(para);
		
		Response.Write(xml2html(dom,Server.MapPath("xsl/mgr.xsl")));
	},
	movetocat : function(){
		var dom = new ActiveXObject("MSXML2.DOMDocument");
		dom.setProperty('SelectionLanguage','XPath');
		dom.load(Server.MapPath("userdata")+"\\"+Request.Cookies("loginUserName")+".xml");		
		var movecat = dom.createNode(1,"movecat","");
		if(RQ("ids")!=""){
			var ids = RQ("ids").split(",");
			for(var i=0; i<ids.length; i++){
				var fav = dom.createNode(1,"fav","");
				fav.text = ids[i];
				movecat.appendChild(fav);
			}
		}
		dom.selectSingleNode("/root").appendChild(movecat);
		Response.Write(xml2html(dom,Server.MapPath("xsl/movetocat.xsl")));
	},
	movetocataction : function(){
		var fid = RF("fid",1);
		var cat = RF("category");
		if(cat==-1){return;}
		var dom = new ActiveXObject("MSXML2.DOMDocument");		
		dom.setProperty('SelectionLanguage','XPath');
		dom.load(Server.MapPath("userdata")+"\\"+Request.Cookies("loginUserName")+".xml");	
		for(var i=0; i<fid.length; i++){
			dom.selectSingleNode("/root/favorites/fav[@id="+fid[i]+"]").setAttribute("catid",cat);
		}
		dom.save(Server.MapPath("userdata")+"\\"+Request.Cookies("loginUserName")+".xml");
		Response.Write("<script type='text/javascript'>window.returnValue='1'; window.close();</script>");
		Response.End();
	},
	catmgr : function(){
		var dom = new ActiveXObject("MSXML2.DOMDocument");		
		dom.load(Server.MapPath("userdata")+"\\"+Request.Cookies("loginUserName")+".xml");	
		Response.Write(xml2html(dom,Server.MapPath("xsl/catmgr.xsl")));
	},
	savecatedit : function(){
		var cid = RF("cid");
		var pid = RF("pid");
		var catname = RF("catname");
		var defaultCat = RF("defaultcat");
		
		var dom = new ActiveXObject("MSXML2.DOMDocument");		
		dom.setProperty("SelectionLanguage", "XPath");
		dom.load(Server.MapPath("userdata")+"\\"+Request.Cookies("loginUserName")+".xml");	
		Response.Write(dom.selectSingleNode("count(/root/favorites//fav)").text);
		Response.End();
		if(cid!=""){
			var node = dom.selectSingleNode("/root/favorites//folder[@guid='"+cid+"']");
			node.setAttribute("name",catname);
			var cats = dom.selectNodes("/root/favorites//folder");
			for(var i=0,len=cats.length; i<len; i++){
				cats[i].setAttribute("default",0);
			}
			if(defaultCat==1){
				node.setAttribute("default",1);
			}
			if(node.parentNode.nodeName=="favorites" && pid!="0"){
				dom.selectSingleNode("/root/favorites//folder[@guid='"+pid+"']").appendChild(node);  //根类降级					
			}else if(node.parentNode.nodeName!="favorites" && node.parentNode.getAttribute("guid")!=pid){
				if(pid=="0"){ //把子类设为根类
					dom.selectSingleNode("/root/favorites").appendChild(node);
				}else{
					dom.selectSingleNode("/root/favorites//folder[@guid='"+pid+"']").appendChild(node);
				}			
			}else{
				var preid = RF("preid");
				var nextid = RF("nextid");
				if(nextid!=""){				
					dom.selectSingleNode("/root/favorites//folder[@guid='"+nextid+"']").parentNode.insertBefore(node,dom.selectSingleNode("/root/favorites//folder[@guid='"+nextid+"']"));
				}else if(preid!=""){
					dom.selectSingleNode("/root/favorites//folder[@guid='"+preid+"']").parentNode.insertBefore(node,dom.selectSingleNode("/root/favorites/folder[@guid='"+preid+"']").nextSibling );
				}
			}
			dom.save(Server.MapPath("userdata")+"\\"+Request.Cookies("loginUserName")+".xml");
			var callback = dom.createNode(1,"callback","");
			callback.text = "1";
			dom.selectSingleNode("/root").appendChild(callback);
		}
		Response.Write(xml2html(dom,Server.MapPath("xsl/catmgr.xsl")));
	},
	catadd : function(){
		var catname = RF("catname");
		if(catname=="未分类"||catname=="全部收藏")Response.Redirect("?type=mgr");
		var dom = new ActiveXObject("MSXML2.DOMDocument");		
		dom.load(Server.MapPath("userdata")+"\\"+Request.Cookies("loginUserName")+".xml");	
		var cat = dom.createNode(1,"cat","");
		cat.setAttribute("id",getMaxID());
		cat.setAttribute("pid","0");
		cat.setAttribute("addtime",getNowTime(4));
		cat.setAttribute("default","0");
		cat.text = catname;
		dom.selectSingleNode("/root/category").appendChild(cat);
		dom.save(Server.MapPath("userdata")+"\\"+Request.Cookies("loginUserName")+".xml");
		Response.Redirect("?type=mgr");
	},
	removefav : function(){
		var fid = RF("fid",1);
		var dom = new ActiveXObject("MSXML2.DOMDocument");		
		dom.load(Server.MapPath("userdata")+"\\"+Request.Cookies("loginUserName")+".xml");	
		var favorites = dom.selectSingleNode("/root/favorites");
		for(var i=0; i<fid.length; i++){
			favorites.removeChild(dom.selectSingleNode("/root/favorites/fav[@id="+fid[i]+"]"));
		}
		dom.save(Server.MapPath("userdata")+"\\"+Request.Cookies("loginUserName")+".xml");
		Response.Redirect("?type=mgr&catid="+RF("cid"));
	},
	removecat : function(){
		var cid = RF("cid");
		if(cid=="")return;
		var dom = new ActiveXObject("MSXML2.DOMDocument");
		dom.load(Server.MapPath("userdata")+"\\"+Request.Cookies("loginUserName")+".xml");
		var cats = dom.selectNodes("/root/category/cat");
		var arr = {};
		var prr = {};
		for(var i=0,len=cats.length; i<len; i++){
			arr[cats[i].getAttribute("id")] = cats[i].getAttribute("pid");
			if(!prr[cats[i].getAttribute("pid")]) prr[cats[i].getAttribute("pid")] = [];
			prr[cats[i].getAttribute("pid")].push(cats[i].getAttribute("id"));
		}
		if(!prr[cid] || prr[cid].length==0){ //无子类
			dom.selectSingleNode("/root/category").removeChild(dom.selectSingleNode("/root/category/cat[@id="+cid+"]"));
			dom.selectNodes("/root/favorites/fav[@catid="+cid+"]").removeAll();
		}else{
			var ids = fav.getloopcid(prr,cid);
			ids.unshift(cid);
			for(var i=0; i<ids.length; i++){
				dom.selectSingleNode("/root/category").removeChild(dom.selectSingleNode("/root/category/cat[@id="+ids[i]+"]"));
				//dom.selectNodes("/root/favorites/fav[@catid="+ids[i]+"]").removeAll();
				var favs = dom.selectNodes("/root/favorites/fav[@catid="+ids[i]+"]");
				for(var j=0; j<favs.length; j++){
					favs[j].setAttribute("catid",0);
				}
			}
		}
		dom.save(Server.MapPath("userdata")+"\\"+Request.Cookies("loginUserName")+".xml");
		var callback = dom.createNode(1,"callback","");
		callback.text = "1";
		dom.selectSingleNode("/root").appendChild(callback);
		Response.Write(xml2html(dom,Server.MapPath("xsl/catmgr.xsl")));
	},
	removecatforever : function(){
	
	},
	getloopcid : function(arr,cid){
		if(!arr[cid])return false;	
		var id = [];
		for(var i=0; i<arr[cid].length; i++){
			id.push( arr[cid][i] );
			var t = fav.getloopcid(arr, arr[cid][i]);
			if(t!==false){
				id.push( t );
			}
		}	
		return id;
	},
	register : function(){
		Response.Write(xml2html("<root/>",Server.MapPath("xsl/register.xsl")));
	},
	registeraction : function(){
		var username = RF("username");
		var password = RF("password");
		var password2 = RF("password2");
		var email = RF("email");
		var strarr = ["用户名不能为空！","请输入密码！","请再次输入密码","两次密码不一致！","邮箱格式不准确！","邮箱不能为空！","该用户名已经被注册！","密码不能少于6位！"];
		var error = "";		
		if(!/.+@.+\..+/.test(email))error = strarr[4];		
		if(email=="") error = strarr[5];
		if(password != password2) error = strarr[3];
		if(password2 == "") error = strarr[2];
		if(password.length<6) error = strarr[7];
		if(password == "") error = strarr[1];
		if(username == "") error = strarr[0];
		var fso = new ActiveXObject("Scripting.FileSystemObject");
		if(fso.FileExists(Server.MapPath("userdata")+"\\"+username.toLowerCase()+".xml")){
			error = strarr[6];
		}
		if(error==""){
			error = "<script type='text/javascript'>alert('注册成功！');setTimeout(function(){document.forms['form1'].action='.'; document.forms['form1'].submit();},50)</script>";
			/*
			<?xml version="1.0" encoding="utf-8"?>
			<root id="1">
				<username>misshjn</username>
				<password>92429d82a41e930486c6de5ebda9602d55c39986</password>
				<addtime>2008-08-02 17:34:07</addtime>
				<email>misshjn@163.com</email>
				<actionip>null</actionip>
				<category/>
				<favorites/>
			</root>
			*/
			var fml = new ActiveXObject("MSXML2.DOMDocument");
			fml.appendChild(fml.createProcessingInstruction("xml","version=\"1.0\" encoding=\"utf-8\""));
			var r = fml.createNode(1,"root","");
			var u = fml.createNode(1,"username","");
			var p = fml.createNode(1,"password","");
			var a = fml.createNode(1,"addtime","");
			var e = fml.createNode(1,"email","");
			var actionip = fml.createNode(1,"actionip","");
			var cate = fml.createNode(1,"category","");
			var favs = fml.createNode(1,"favorites","");
			u.text = username;
			p.text = hex_sha1(password);
			a.text = getNowTime(4);
			e.text = email;
			actionip.text = Request.ServerVariables("REMOTE_ADDR")+"";
			r.appendChild(u);
			r.appendChild(p);
			r.appendChild(a);
			r.appendChild(e);
			r.appendChild(actionip);
			r.appendChild(cate);
			r.appendChild(favs);
			fml.appendChild(r);
			fml.save(Server.MapPath("userdata")+"\\"+username.toLowerCase()+".xml");
		}
		var dom = new ActiveXObject("MSXML2.DOMDocument");
		var root = dom.createNode(1,"root","");
		var err = dom.createNode(1,"error","");
		err.text = error;
		var user = dom.createNode(1,"username","");
		var pass = dom.createNode(1,"password","");
		var pass2 = dom.createNode(1,"password2","");
		var email = dom.createNode(1,"email","");
		user.text = RF("username");
		pass.text = RF("password");
		pass2.text = RF("password2");
		email.text = RF("email");
		root.appendChild(user);
		root.appendChild(pass);
		root.appendChild(pass2);
		root.appendChild(email);
		root.appendChild(err);
		dom.appendChild(root);
		Response.Write(xml2html(dom,Server.MapPath("xsl/register.xsl")));
	},
	addfavui : function(){
		var dom = new ActiveXObject("MSXML2.DOMDocument");		
		dom.load(Server.MapPath("userdata")+"\\"+Request.Cookies("loginUserName")+".xml");
		Response.Write(xml2html(dom,Server.MapPath("xsl/add.xsl")));
	},
	addfav : function(){
		var dom = new ActiveXObject("MSXML2.DOMDocument");		
		dom.load(Server.MapPath("userdata")+"\\"+Request.Cookies("loginUserName")+".xml");
		var title = RF("title");
		var url = RF("url").toLowerCase();
		var cat = RF("category");
		var error = dom.createNode(1,"error","");
		error.text = "";
		if(title==""){
			error.text = "标题不能为空！";
		}else if(url==""){
			error.text = "链接不能为空！";
		}else if(!/(http:\/\/|https:\/\/)+/i.test(url) ){
			error.text = "链接地址格式错误！必须以 http:// 开头。";
		}
		if(error.text==""){
			//<fav id="28893" url="http://www.999net.com/network/xml/200901/5473_2.html" viewtime="" catid="329" actionip="219.134.1.206" import="0" addtime="2009-07-24 10:18:13" clicktimes="0" title="利用XSLT把ADO记录集转换成XML-Xml编程-网络编程-源码动力"/>
			if(dom.selectSingleNode("/root/favorites/fav[@url='"+url+"']")){
				error.text = "<script type='text/javascript'>alert('地址已经存在！');window.close();</script>";;
			}else{
				var fav = dom.createNode(1,"fav","");
				fav.setAttribute("id",getMaxID());
				fav.setAttribute("url",url);
				fav.setAttribute("viewtime","");
				fav.setAttribute("catid",cat);
				fav.setAttribute("actionip",Request.ServerVariables("REMOTE_ADDR")+"");
				fav.setAttribute("import",0);
				fav.setAttribute("addtime",getNowTime(4));
				fav.setAttribute("clicktime",0);
				fav.setAttribute("title",title);
				if(dom.selectSingleNode("/root/favorites/fav")){
					dom.selectSingleNode("/root/favorites").insertBefore(fav,dom.selectSingleNode("/root/favorites/fav"));
				}else{
					dom.selectSingleNode("/root/favorites").appendChild(fav);
				}
				dom.save(Server.MapPath("userdata")+"\\"+Request.Cookies("loginUserName")+".xml");		
				error.text = "<script type='text/javascript'>alert('添加成功！');window.close();</script>";
			}
		}
		dom.selectSingleNode("/root").appendChild(error);
		var addform = dom.createNode(1,"addform","");
		var t = dom.createNode(1,"title","");
		var u = dom.createNode(1,"url","");
		var c = dom.createNode(1,"cat","");
		t.text = title;
		u.text = url;
		c.text = cat;
		addform.appendChild(t);
		addform.appendChild(u);
		addform.appendChild(c);
		dom.selectSingleNode("/root").appendChild(addform);
		Response.Write(xml2html(dom,Server.MapPath("xsl/add.xsl")));
	},
	importFav : function(){
		var dom = new ActiveXObject("MSXML2.DOMDocument");		
		dom.load(Server.MapPath("userdata")+"\\"+Request.Cookies("loginUserName")+".xml");
		Response.Write(xml2html(dom,Server.MapPath("xsl/import.xsl")));
	},
	importdata : function(){
		var favxml = new ActiveXObject("MSXML2.DOMDocument");
		favxml.load(Request);		
		var ids = getMaxID(favxml.selectNodes("/root//cat").length + favxml.selectNodes("/root//fav").length).split(",");		
		var addtime = getNowTime(4);
		var ip = Request.ServerVariables("REMOTE_ADDR")+"";
		var cats = favxml.selectNodes("/root//cat");
		for(var i=0,len=cats.length; i<len; i++){
			cats[i].setAttribute("id",ids.shift());
		}
		for(var i=0,len=cats.length; i<len; i++){
			cats[i].setAttribute("pid",cats[i].parentNode.nodeName=="cat" ? (cats[i].parentNode.getAttribute("id")+"") : RQ("pid"));
		}
		var favs = favxml.selectNodes("/root//fav");
		for(var i=0,len=favs.length; i<len; i++){
			favs[i].setAttribute("id",ids.shift());
			favs[i].setAttribute("catid",favs[i].parentNode.nodeName=="cat" ? (favs[i].parentNode.getAttribute("id")+"") : RQ("pid"));
		}
				
		var dom = new ActiveXObject("MSXML2.DOMDocument");
		dom.load(Server.MapPath("userdata")+"\\"+Request.Cookies("loginUserName")+".xml");
		//<cat id="117" pid="0" addtime="" default="0">常用网址</cat>
		var category = dom.selectSingleNode("/root/category");
		for(var i=0,len=cats.length; i<len; i++){
			var cat = dom.createNode(1,"cat","");
			cat.setAttribute("id",cats[i].getAttribute("id"));
			cat.setAttribute("pid",cats[i].getAttribute("pid"));
			cat.setAttribute("addtime",addtime);
			cat.setAttribute("default","0");
			cat.setAttribute("import","1");
			cat.text = cats[i].getAttribute("name");
			category.appendChild(cat);
		}
		//<fav id="28893" url="http://www.999net.com/network/xml/200901/5473_2.html" viewtime="" catid="329" actionip="219.134.1.206" import="0" addtime="2009-07-24 10:18:13" clicktimes="0" title="利用XSLT把ADO记录集转换成XML-Xml编程-网络编程-源码动力"/>
		var favorites = dom.selectSingleNode("/root/favorites");
		for(var i=0,len=favs.length; i<len; i++){
			var fav = dom.createNode(1,"fav","");
			fav.setAttribute("id",favs[i].getAttribute("id"));
			fav.setAttribute("catid",favs[i].getAttribute("catid"));
			fav.setAttribute("url",favs[i].getAttribute("url"));
			fav.setAttribute("viewtime","0");
			fav.setAttribute("actionip",ip);
			fav.setAttribute("import","1");
			fav.setAttribute("addtime",addtime);
			fav.setAttribute("clicktimes","0");
			fav.setAttribute("title",favs[i].getAttribute("name"));
			favorites.insertBefore(fav,favorites.firstChild);
		}
		dom.save(Server.MapPath("userdata")+"\\"+Request.Cookies("loginUserName")+".xml");
		Response.Write(1);
		//Response.Write(dom.selectNodes("/root//fav").length);
	}
};


/*===============================================================================================================================*/
var type = RQ("type").toLowerCase();
switch(type){
	case "loginui": 
		fav.loginui();
		break;
	case "login":		
		fav.login();
		break;
	case "logout":
		fav.logout();
		break;
	case "mgr":
		fav.checkLogin() && fav.mgr();
		break;
	case "movetocat":
		fav.movetocat();
		break;
	case "movetocataction":
		fav.movetocataction();
		break;
	case "catmgr" : 
		fav.catmgr();
		break;
	case "savecatedit":
		fav.savecatedit();
		break;
	case "catadd":
		fav.catadd();
		break;
	case "removecat" : 
		fav.removecat();
		break;
	case "removecatforever" :
		fav.removecatforever();
		break;
	case "removefav" : 
		fav.removefav();
		break;
	case "register" :
		fav.register();
		break;
	case "registeraction" :
		fav.registeraction();
		break;
	case "addfavui" :
		fav.addfavui();
		break;
	case "addfav" :
		fav.addfav();
		break;
	case "import" :
		fav.importFav();
		break;
	case "importdata" : 
		fav.importdata();
		break;
	default : 	
		fav.logout();
		break;		
}
%>